package com.hzcx.app.simplechat.ui.publicui;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseActivity;
import com.hzcx.app.simplechat.chat.ChatUtil;
import com.hzcx.app.simplechat.chat.constant.ChatConstant;
import com.hzcx.app.simplechat.common.Common;
import com.hzcx.app.simplechat.common.CommonSp;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.ui.chat.ChatShareUserActivity;
import com.hzcx.app.simplechat.ui.chat.event.ChatShareUserEvent;
import com.hzcx.app.simplechat.ui.login.event.WxLoginSuccessEvent;
import com.hzcx.app.simplechat.ui.main.MainActivity;
import com.hzcx.app.simplechat.ui.publicui.bean.ProtocolBean;
import com.hzcx.app.simplechat.ui.publicui.bean.ShareInfoBean;
import com.hzcx.app.simplechat.ui.publicui.contract.ShareContract;
import com.hzcx.app.simplechat.ui.publicui.presenter.SharePresenter;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.NavigationBarInfo;
import com.hzcx.app.simplechat.util.app.AppHelper;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.log.LogUtils;
import com.hzcx.app.simplechat.util.sp.SPUtils;
import com.hzcx.app.simplechat.util.toast.ToastUtils;
import com.hzcx.app.simplechat.util.wx.WxShareUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 分享弹窗
 */
public class PrivacyActivity extends BaseActivity {

    public static final String INTENT_USER_ID = "INTENT_USER_ID";

    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.tv_hint)
    TextView tvHint;
    ProtocolBean data;


    @Override
    public int getLayout() {
        return R.layout.dialog_privacy;
    }

    @Override
    public void initPresenter() {
    }

    @Override
    public void initView() {

        // 显示在最底部
        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        int height= NavigationBarInfo.getNavigationBarHeight(this);
        LogUtils.d("height:"+height);
        if(height<50){
            height=0;
        }
        WindowManager.LayoutParams params=getWindow().getAttributes();
        params.y=height;

        tvSure.setOnClickListener(view -> {
            SPUtils.putBoolean( CommonSp.LOGIN_FIRST,false);
            finish();
        });
        tvCancel.setOnClickListener(view->{
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
        });

        PublicModel.getProtocolByType(this, "policy", new BaseObserver<ProtocolBean>() {
            @Override
            protected void onSuccess(ProtocolBean data) {
                PrivacyActivity.this.data = data;
            }
        });

    }

    @Override
    public void initData() {
        SpannableString spannableString = new SpannableString("如您同意《多聊隐私政策》请点击“同意”开始使用我们的产品和服务，我们尽全力保护您的个人信息安全");

        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.color_privacy));

        ClickableSpan clickableSpan = new ClickableSpan() {

            @Override

            public void onClick(View widget) {
                if (data!=null){
                    startActivity(new Intent(PrivacyActivity.this, WebViewActivity.class)
                            .putExtra(WebViewActivity.INTENT_TITLE, data.getName())
                            .putExtra(WebViewActivity.INTENT_WEB_URL, data.getContenturl()));
                }

            }

            @Override

            public void updateDrawState(TextPaint ds) {

                ds.setUnderlineText(false);

            }

        };
        spannableString.setSpan(foregroundColorSpan, 4, 12, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(clickableSpan, 4, 12, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tvHint.setHighlightColor(getResources().getColor(android.R.color.transparent));
        tvHint.setMovementMethod(LinkMovementMethod.getInstance());
        tvHint.setText(spannableString);
    }



}
